﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;

namespace TS_XY_Train_Repaire.UserCon.Stuff
{
    public partial class uc_Stuff_Department_ManaForm : DevExpress.XtraEditors.XtraForm
    {
        public string _LoadID = "";
        public string _LoadRbid = "";
        public string _LoadDeep = "";
        public string _LoadLevel = "";
        public string _LoadRsid = "";
        public string _LoadName = "";
        public string _LoadCode = "";
        public string _LoadType = "";
        public uc_Stuff_Department_ManaForm()
        {
            InitializeComponent();
        }

        private void uc_Stuff_Department_ManaForm_Load(object sender, EventArgs e)
        {
            tb_Code.Text = _LoadCode;
            tb_Name.Text = _LoadName;
            switch (_LoadType)
            {
                case "Add":
                    bt_Sure.Text = "新增一级部门";
                    break;
                case "Sub_Add":
                    bt_Sure.Text = "新增子部门";
                    break;
                case "Edit":
                    bt_Sure.Text = "修改部门";
                    break;
                case "Del":
                    bt_Sure.Text = "删除部门";
                    break;
            }
        }
        private void tb_Name_TextChanged(object sender, EventArgs e)
        {
            if (tb_Code.Text.Trim().Length > 0 && tb_Name.Text.Trim().Length > 0)
            {
                bt_Sure.Enabled = true;
            }
            else
            {
                bt_Sure.Enabled = false;
            }
        }

        private void bt_Exit_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
        }

        private void bt_Sure_Click(object sender, EventArgs e)
        {
            string strSQL = "";
            switch (_LoadType)
            {
                case "Add":
                    strSQL = "insert into TS_S_T_P_Department (f_name,f_code,f_rbid,f_rsid,f_deep,f_level,f_workerid) values('" + tb_Name.Text.Trim() + "','" + tb_Code.Text.Trim() + "'," + _LoadRbid + "," + _LoadRsid + ",0,','," + TS_Win_Locomotive_MainForm.pUserInfoMain.GuId + ")";
                    break;
                case "Sub_Add":
                    strSQL = "insert into TS_S_T_P_Department (f_name,f_code,f_rbid,f_rsid,f_deep,f_level,f_workerid) values('" + tb_Name.Text.Trim() + "','" + tb_Code.Text.Trim() + "'," + _LoadRbid + "," + _LoadRsid + ","+(Convert.ToInt32(_LoadDeep)+1).ToString()+",'"+_LoadLevel+_LoadID.Substring(1)+",'," + TS_Win_Locomotive_MainForm.pUserInfoMain.GuId + ")";
                    break;
                case "Edit":
                    strSQL = "update TS_S_T_P_Department set f_name='" + tb_Name.Text.Trim() + "',f_code='" + tb_Code.Text.Trim() + "',f_workerid=" + TS_Win_Locomotive_MainForm.pUserInfoMain.GuId + ",f_time=getdate() where f_id=" + _LoadID.Substring(1);
                    break;
                case "Del":
                    strSQL = "update TS_S_T_P_Department set f_del=1,f_workerid=" + TS_Win_Locomotive_MainForm.pUserInfoMain.GuId + ",f_time=getdate() where f_id=" + _LoadID.Substring(1);
                    break;
            }
            TS_Win_Class.MySqlCom(strSQL);
            this.DialogResult = DialogResult.OK;
        }

    }
}